package com.heima;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;

//大浮点
public class BigDecimalTest {
    public static void main(String[] args) {
        BigDecimal count = BigDecimal.valueOf(0);//创建大浮点的对象。一共有两种有参的是String类型的参数
        double[] arr =  {0.1,0.2,2.1,3.2,5.56,7.21};
        for (int i = 0; i < arr.length; i++) {
            count = count.add(BigDecimal.valueOf(arr[i]));
        }
        BigDecimal divide = count.divide(BigDecimal.valueOf(arr.length), 2, RoundingMode.HALF_UP);
        double val = divide.doubleValue();//转换为double类型
        System.out.println("数组的平均值为"+val);

    }
}
